#include<bits/stdc++.h>
using namespace std;
const int N = 1010;
int dr[4] = {0 , 1 , 0 , -1};
int dc[4] = {1 , 0 , -1 , 0};
int v1[N][N] , v2[N][N];
void work(){
	int lin = 1 , hua = 1;
	int n , r1 , c1 , d1 , r2 , c2 , d2;
	cin >> n >> r1 >> c1 >> d1 >> r2 >> c2 >> d2;
	r1++;
	c1++;
	r2++;
	c2++;
	memset(v1 , 0 , sizeof(v1));
	memset(v2 , 0 , sizeof(v2));
	for(int i = 1 ; i <= n ; i++){
		for(int j = 1 ; j <= n ; j++){
			v1[i][j] = 1;
			v2[i][j] = 1;
		}
	}
	if(r1 == r2 && c1 == c2){
		cout << r1 - 1 << ' ' << c1 - 1 << endl;
		return;
	}
	v1[r1][c1] = 0;
	v2[r2][c2] = 0;
	while(lin || hua){
		if(lin){
			int tr1 = r1 + dr[d1];
			int tc1 = c1 + dc[d1];
			if(v1[tr1][tc1] == 0){
				d1 = (d1 + 1) % 4;
				tr1 = r1 + dr[d1];
				tc1 = c1 + dc[d1];
				if(v1[tr1][tc1] == 0) lin = 0;
				else{
					r1 = tr1;
					c1 = tc1;
				}
			}
			else{
				r1 = tr1;
				c1 = tc1;
			}
		}
		if(hua){
			int tr2 = r2 + dr[d2];
			int tc2 = c2 + dc[d2];
			if(v2[tr2][tc2] == 0){
				d2 = (d2 + 3) % 4;
				tr2 = r2 + dr[d2];
				tc2 = c2 + dc[d2];
				if(v2[tr2][tc2] == 0) hua = 0;
				else{
					r2 = tr2;
					c2 = tc2;
				}
			}
			else{
				r2 = tr2;
				c2 = tc2;
			}
		}
		v1[r1][c1] = 0;
		v2[r2][c2] = 0;
		if(r1 == r2 && c1 == c2){
			cout << r1 - 1 << ' ' << c1 - 1 << endl;
			return;
		}
	}
	cout << "-1" << endl;
}
int main(){
	freopen("fight.in" , "r" , stdin);
	freopen("fight.out" , "w" , stdout);
	int t;
	cin >> t;
	while(t--){
		work();
	}
	return 0;
}
